package Zoo.View.UserView;

import Zoo.Entity.UserEntity;
import Zoo.Handler.UpdateUserViewHandler;

import javax.swing.*;
import java.awt.*;

public class UpdateUserView extends JDialog {
    JPanel jPanel=new JPanel();

    JLabel idLable =new JLabel("用户id");
    JTextField idTxt=new JTextField();


    JLabel nameLable =new JLabel("新用户名");
    JTextField nameTxt=new JTextField();
    JLabel pwdLable =new JLabel("密码");
    JTextField pwdTxt=new JTextField();
    JLabel phoneLable =new JLabel("联系方式");
    JTextField phoneTxt=new JTextField();
    JButton updateBtn =new JButton("修改");

    UpdateUserViewHandler updateUserViewHandler;
    public UpdateUserView(UserView userView){
        super(userView,"修改用户信息",true);

        updateUserViewHandler=new UpdateUserViewHandler(this,userView);
        idLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(idLable);
        idTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(idTxt);

        nameLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(nameLable);
        nameTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(nameTxt);



        pwdLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(pwdLable);
        pwdTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(pwdTxt);



        phoneLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(phoneLable);
        phoneTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(phoneTxt);


        Container contentPane=getContentPane();
        contentPane.add(jPanel);
        updateBtn.addActionListener(updateUserViewHandler);
        jPanel.add(updateBtn);

        setSize(350,500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }

    public UserEntity buildUpdatedUserEntity() {
        UserEntity userEntity=new UserEntity();
        userEntity.setId(Integer.valueOf(idTxt.getText()));
        userEntity.setUsername(nameTxt.getText());
        userEntity.setPwd(pwdTxt.getText());
        userEntity.setPhone(phoneTxt.getText());

        return userEntity;
    }
}
